package com.apes.hr.base.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 功能：请假信息
 * @author zyh
 * @create 2018-04-25 15:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = Leave.CONST_TABLE_NAME)
public class Leave extends Model {
    public static final String CONST_TABLE_NAME = "hr_leave";

    @Id
    @Column(name = "id", nullable = false, length = 120)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "请假单号", padding = 8)
    private String id; //请假编码


    @Name
    @Column(name = "name", nullable = false, length = 200)
    private String name; //请假事项


    @Column(name = "endDate")
    private Date endDate; //结束时间

    @Column(name = "startDate")
    private Date startDate; //开始时间

    
    @ManyToOne(optional = false)
    @JoinColumn(name = "Employee_id", referencedColumnName = "id")
    private Employee employee; //请假人员


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    private PartyRole company; //公司编码


    @Column(name = "state", length = 10)
    private String state;
    //状态： ('create', '创建'), ('stop', '停单'), ('transStop', '转停单'),
    // ('end', '结单'), ('delete','删除')


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "zssp_id", referencedColumnName = "id")
    private PartyRole zsspId; //直属审批人


    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "zssp_date")
    private Date zsspDate;    // 直属审批日期


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "spr_id", referencedColumnName = "id")
    private PartyRole sprId; //审批人


    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "spr_date")
    private Date sprDate;    // 审批日期


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "delete_id", referencedColumnName = "id")
    private PartyRole deleteId; //删除人


    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "delete_date")
    private Date deleteDate;    // 删除日期


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "initiat_oa_id", referencedColumnName = "id")
    private PartyRole initiatOaId; //oa发起人

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "initiat_oa_date")
    private Date initiatOaDate;    // oa发起时间

    @Column(name = "next_dispose_sign", length = 120)
    private String nextDisposeSign;  //处理节点候选人

}
